/**
 * Items collection
 */
Todo.Collection.Item = Todo.Collection.Base.extend({
    // Reference to this collection's model.
    model: Todo.Model.Item,

    /**
     * Filter items by category
     * @param categoryId
     * @return {Todo.Collection.Item}
     */
    getByCategory: function (categoryId) {
        return new Todo.Collection.Item(
            this.filter(function (item) {
                if (categoryId) {
                    return item.get('category_id') == categoryId;
                } else {
                    return !item.get('category_id') || item.get('category_id') == 0;
                }
            })
        );
    },

    /**
     * Filter items by type
     * @param type
     * @return {Todo.Collection.Item}
     */
    getByType: function (type) {
        return new Todo.Collection.Item(
            this.filter(function (item) {
                switch (type) {
                    case 'due':
                        return item.get('expired');
                        break;

                    case 'date':
                        return item.get('deadline');
                        break;

                    case 'other':
                        return !item.get('deadline') && !item.get('expired');
                        break;
                }
            })
        );
    }
});